﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonaLibrary.ViewModel
{
    /*
    public abstract class OrderByCollection<T>
        where T : DataModel.Entity
    {
        public OrderByCollection()
            : base()
        { }

        private string orderPropertyName;

        public string OrderPropertyName
        {
            set
            {
                orderPropertyName = value;
                risePropertyChanged("OrderPropertyName");
                OnOrderByChanged();
            }
            get
            {
                return orderPropertyName;
            }
        }

        public System.Linq.Expressions.Expression<Func<T, object>> OrderExpression
        {
            get
            {
                if (!string.IsNullOrEmpty(OrderPropertyName))
                {
                    var param = System.Linq.Expressions.Expression.Parameter(typeof(T), "x");
                    var mySortExpression
                        = System.Linq.Expressions.Expression.Lambda<Func<T, object>>(System.Linq.Expressions.Expression.Property(param, orderPropertyName), param);
                    return mySortExpression;
                }
                else
                {
                    var param = System.Linq.Expressions.Expression.Parameter(typeof(T), "x");
                    return x => " ";
                }
            }
        }

        protected override Type RepositoryType
        {
            get { throw new NotImplementedException(); }
        }

        protected virtual void OnOrderByChanged()
        {
            Refresh();
        }

        public override void Refresh()
        {
            IsEditable = false;
            Collection = Repository.GetAll();
            Collection.LoadComplite += delegate 
            { 
                IsEditable = true;
                Collection.AsQueryable().OrderBy(OrderExpression);
                risePropertyChanged("Collection");
            };
            Collection.Load();
        }
    }*/
}
